// const cloud = require("wx-server-sdk")
// cloud.init({
//     env: cloud.DYNAMIC_CURRENT_ENV
// })
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
const dbCmd = db.command;
exports.main = async (event, context) => {
    var list = [];
    if (event.name == "") {
        list = await db.collection("chinawealth").get();
    } else {
        list = await db.collection("chinawealth")
            .where({
                name: new db.RegExp({
                    regexp: event.name,
                    options: "i",
                })
            }).get();
    }
    return {
        list: list.data
    }
}

// // 云函数入口文件
// const cloud = require('wx-server-sdk')

// cloud.init()

// // 云函数入口函数
// exports.main = async (event, context) => {
//     const wxContext = cloud.getWXContext()

//     return {
//         event,
//         openid: wxContext.OPENID,
//         appid: wxContext.APPID,
//         unionid: wxContext.UNIONID,
//     }
// }